<?php

namespace App\Http\Resources\goods;

use App\Models\goods\Goods;
use Illuminate\Http\Resources\Json\ResourceCollection;


class GoodsResource extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {

        return $this->collection->map(function (Goods $item) {
            return [
                'id' => $item->id,
                'img' => $item->img??'',
                'name' => $item->name,
                'stock' => $item->stock,
                'integral' => (int)$item->price,
            ];
        });
    }
}
